package org.jeecg.modules.customer.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.customer.entity.UsrUserInfo;
import org.jeecg.modules.customer.service.IUsrUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
* @Description: 会员信息
* @Author: jeecg-boot
* @Date:   2020-05-02
* @Version: V1.0
*/
@Slf4j
@Api(tags="会员信息")
@RestController
@RequestMapping("/user/usrUserInfo")
public class UsrUserInfoController extends JeecgController<UsrUserInfo, IUsrUserInfoService> {
   @Autowired
   private IUsrUserInfoService usrUserInfoService;

   /**
    * 分页列表查询
    *
    * @param usrUserInfo
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   @AutoLog(value = "用户信息-分页列表查询")
   @ApiOperation(value="用户信息-分页列表查询", notes="用户信息-分页列表查询")
   @GetMapping(value = "/queryUserList")
   public Result<?> queryUserList(UsrUserInfo usrUserInfo,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<UsrUserInfo> queryWrapper = QueryGenerator.initQueryWrapper(usrUserInfo, req.getParameterMap());
       Page<UsrUserInfo> page = new Page<UsrUserInfo>(pageNo, pageSize);
       IPage<UsrUserInfo> pageList = usrUserInfoService.page(page, queryWrapper);
       return Result.ok(pageList);
   }

   /**
    * 添加
    *
    * @param usrUserInfo
    * @return
    */
   @AutoLog(value = "用户信息-添加")
   @ApiOperation(value="用户信息-添加", notes="用户信息-添加")
   @PostMapping(value = "/add")
   public Result<?> add(@RequestBody UsrUserInfo usrUserInfo) {
       usrUserInfoService.save(usrUserInfo);
       return Result.ok("添加成功！");
   }

   /**
    * 编辑
    *
    * @param usrUserInfo
    * @return
    */
   @AutoLog(value = "用户信息-编辑")
   @ApiOperation(value="用户信息-编辑", notes="用户信息-编辑")
   @PutMapping(value = "/edit")
   public Result<?> edit(@RequestBody UsrUserInfo usrUserInfo) {
       usrUserInfoService.updateById(usrUserInfo);
       return Result.ok("编辑成功!");
   }

   /**
    *
    * @param userId
    * @param isRemark
    * @return
    */
   @AutoLog(value = "用户信息-是否禁止评论")
   @ApiOperation(value="用户信息-是否禁止评论")
   @GetMapping(value = "/shutdownRemark")
   public Result<?> shutdownRemark(String userId,int isRemark){
       UsrUserInfo user = new UsrUserInfo();
       user.setUserId(userId);
       user.setIsRemark(isRemark);
       usrUserInfoService.updateById(user);
       return Result.ok("修改成功!");
   }

   /**
    * 通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "用户信息-通过id删除")
   @ApiOperation(value="用户信息-通过id删除", notes="用户信息-通过id删除")
   @DeleteMapping(value = "/delete")
   public Result<?> delete(@RequestParam(name="id",required=true) String id) {
       usrUserInfoService.removeById(id);
       return Result.ok("删除成功!");
   }

   /**
    * 批量删除
    *
    * @param ids
    * @return
    */
   @AutoLog(value = "用户信息-批量删除")
   @ApiOperation(value="用户信息-批量删除", notes="用户信息-批量删除")
   @DeleteMapping(value = "/deleteBatch")
   public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
       this.usrUserInfoService.removeByIds(Arrays.asList(ids.split(",")));
       return Result.ok("批量删除成功！");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @AutoLog(value = "用户信息-通过id查询")
   @ApiOperation(value="用户信息-通过id查询", notes="用户信息-通过id查询")
   @GetMapping(value = "/queryById")
   public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
       UsrUserInfo usrUserInfo = usrUserInfoService.getById(id);
       return Result.ok(usrUserInfo);
   }

}
